<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>四川麻将-血战到底</title>
    <style>
        /* 在原有样式基础上添加四川麻将特有元素 */
        .sichuan-rules {
            background: #fff3e0;
            border-left: 4px solid #ff9800;
            padding: 15px;
            margin: 15px 0;
        }
        .gang-counter {
            color: #d32f2f;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <h1 class="game-title">四川麻将-血战到底</h1>
        
        <!-- 新增四川麻将特有规则说明 -->
        <div class="sichuan-rules">
            <h3>特色规则：</h3>
            <ul>
                <li>血战到底：必须打完所有牌</li>
                <li>刮风下雨：杠牌立即计分</li>
                <li>缺一门：必须缺一门花色</li>
            </ul>
        </div>
        
        <!-- 新增杠牌计数器 -->
        <div class="score-area">
            <div class="score gang-counter">当前杠数: <span id="gang-count">0</span></div>
        </div>
    </div>
    
    <script>
        // 四川麻将特有规则实现
        // 配置化游戏参数
const GAME_CONFIG = {
  SCORES: {
    AN_GANG: 2,
    MING_GANG: 1,
    BLOOD_PHASE_MULTIPLIER: [1, 1.5, 2, 2.5]
  },
  MAX_PHASE: 4
};

const SICHUAN_RULES = {
            REQUIRED_MISSING_SUIT: true, // 必须缺一门
            GANG_SCORES: { // 杠牌得分规则
                AN_GANG: 2,   // 暗杠
                MING_GANG: 1  // 明杠
            }
        };

        // 扩展游戏状态
        let gameState = {
            ...gameState,
            missingSuit: null,  // 玩家选择的缺门花色
            gangCount: 0,       // 总杠数
            gangHistory: [],    // 杠牌记录（使用TypeScript类型增强）
/** @type {Array<{type: 'AN_GANG'|'MING_GANG', bonus: number, timestamp: number}>} */
            currentGangBonus: 0 // 当前杠累积分数
        };

        // 血战到底阶段标识
        let bloodBattlePhase = 1;

        // 新增缺门选择功能
        function selectMissingSuit(suit) {
            gameState.missingSuit = suit;
            // 移除该花色所有牌
            gameState.playerHand = gameState.playerHand.filter(
                tile => !tile.type.startsWith(suit)
            );
            updateUI();
        }

        // 重写匹配逻辑
        function checkMatch() {
            const [tile1, tile2] = gameState.selectedTiles;
            
            // 四川麻将特殊匹配规则
            if (tile1.type === tile2.type) {
                handleGang(tile1.type);
                gameState.score += calculateGangScore();
                // 更新状态显示...
            }
        }

        // 杠牌处理（刮风下雨）
        function handleGang(tileType) {
            const gangTiles = gameState.playerHand.filter(t => t.type === tileType);
            
            if (gangTiles.length >= 3) {
                const gangType = gangTiles.length === 4 ? 'AN_GANG' : 'MING_GANG';
                const phaseMultiplier = GAME_CONFIG.SCORES.BLOOD_PHASE_MULTIPLIER[bloodBattlePhase - 1];
const bonus = GAME_CONFIG.SCORES[gangType] * phaseMultiplier;
                
                gameState.gangCount++;
                gameState.currentGangBonus += bonus;
                gameState.gangHistory.push({
                    type: gangType,
                    tiles: gangTiles,
                    bonus: bonus
                });
                
                // 更新阶段
                bloodBattlePhase = Math.min(bloodBattlePhase + 1, GAME_CONFIG.MAX_PHASE);
                updateGangDisplay();
            }
        }

        // 更新杠牌显示
        function updateGangDisplay() {
            document.getElementById('gang-details').innerHTML = gameState.gangHistory
                .map(g => `${g.type} +${g.bonus}`)
                .join('<br>');
        }

        // 分数计算
        function calculateGangScore() {
            return gameState.gangHistory.reduce(
                (sum, gang) => sum + SICHUAN_RULES.GANG_SCORES[gang.type], 0
            );
        }
    </script>
</body>
</html>